package com.fuershiye.woman.monitor.utils;

import java.util.List;
import com.fuershiye.woman.monitor.model.Indicator;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;

public class IndicatorUtil {

	
	public static Indicator findIndicator(Long id, List<Indicator> all) {
		if(id==null||id==0){
			return null;
		}
		for (Indicator indicator : all) {
			if(id.equals(indicator.getId())){
				return indicator;
			}
		}
		return null;
	}

	public static List<Integer> getIdFromIndicators(List<Indicator> all) {

		if(all.isEmpty()){
			return null;
		}
		List<Integer> result = Lists.newArrayList();
		for (Indicator indicator : all) {
			if(null!=indicator.getId()){
				result.add(indicator.getId().intValue());
			}
		}
		return result;
	}

	public static List<Long> getIds(String indicatorIds) {


		String[] all = indicatorIds.split(",");

		if(all.length<1){
			return null;
		}
		List<Long> result = Lists.newArrayList();
		for (String indicator : all) {
			if(StringUtils.isNotEmpty(indicator)){
				result.add(Long.valueOf(indicator));
			}
		}
		return result;
	}

	public static void main(String[] args) throws Exception {
//		System.out.println(getRate(130d, 71d));
		System.out.println(getIds("1,2,3,4,5"));
	}

}